<template>
  <view class="container">
    <!-- 背景渐变区域 -->
    <view class="header-bg">
      <view class="title">智慧农业助手</view>
      <view class="subtitle">走进智慧农业，创建幸福生活</view>
    </view>
    
    <!-- 登录卡片 -->
    <view class="login-card">
      <!-- 登录方式选项卡 -->
      <view class="login-tabs">
        <view class="tab active">
          <text>账号密码登录</text>
          <view class="tab-line"></view>
        </view>
        <view class="tab">
          <text>手机验证码登录</text>
        </view>
      </view>
      
      <!-- 登录表单 -->
      <view class="login-form">
        <view class="input-item">
          <uni-icons type="person" size="20" color="#999"></uni-icons>
          <input type="text" placeholder="请输入用户名/手机号" v-model="loginForm.username" />
        </view>
        <view class="input-item">
          <uni-icons type="locked" size="20" color="#999"></uni-icons>
          <input type="password" placeholder="请输入密码" v-model="loginForm.password" />
        </view>
        
        <button class="login-btn" @click="handleLogin">登 录</button>
      </view>
    </view>
    
    <!-- 第三方登录 -->
    <view class="third-party-login">
      <view class="third-party-title">使用第三方账号登录</view>
      <view class="third-party-icons">
        <view class="icon-item">
          <image src="/static/qq.png" mode="widthFix" class="third-icon"></image>
        </view>
        <view class="icon-item">
          <image src="/static/wechat.png" mode="widthFix" class="third-icon"></image>
        </view>
        <view class="icon-item">
          <image src="/static/weibo.png" mode="widthFix" class="third-icon"></image>
        </view>
      </view>
      
      <view class="mobile-login-link">
        <text>没有账号？</text>
        <text class="link-text">手机号快捷登录</text>
      </view>
    </view>
  </view>
</template>

<script setup>
import { reactive } from 'vue';
import { onLoad } from '@dcloudio/uni-app';

// 登录表单数据
const loginForm = reactive({
  username: '',
  password: ''
});

// 生命周期钩子
onLoad(() => {
  console.log('登录页面加载完成');
});

// 登录方法
const handleLogin = () => {
  if (!loginForm.username) {
    uni.showToast({
      title: '请输入用户名/手机号',
      icon: 'none'
    });
    return;
  }
  
  if (!loginForm.password) {
    uni.showToast({
      title: '请输入密码',
      icon: 'none'
    });
    return;
  }
  
  // 这里添加实际登录逻辑
  console.log('登录表单提交', loginForm);
  uni.showLoading({
    title: '登录中...'
  });
  
  // 模拟登录请求
  setTimeout(() => {
    uni.hideLoading();
    uni.showToast({
      title: '登录成功',
      icon: 'success'
    });
    
    // 登录成功后跳转到首页
    setTimeout(() => {
      uni.switchTab({
        url: '/pages/index/index'
      });
    }, 1500);
  }, 2000);
};
</script>

<style>
.container {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: #ffffff;
}

.header-bg {
  width: 100%;
  height: 200px;
  background: linear-gradient(180deg, #6DD4CE 0%, #B3E5E1 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: 40px;
}

.title {
  font-size: 28px;
  color: #ffffff;
  font-weight: bold;
}

.subtitle {
  font-size: 16px;
  color: #ffffff;
  margin-top: 10px;
}

.login-card {
  width: 90%;
  background-color: #ffffff;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  margin-top: -20px;
  padding: 20px;
}

.login-tabs {
  display: flex;
  border-bottom: 1px solid #eee;
  padding-bottom: 15px;
}

.tab {
  flex: 1;
  text-align: center;
  font-size: 15px;
  color: #666;
  position: relative;
}

.tab.active {
  color: #44C0B7;
  font-weight: bold;
}

.tab-line {
  position: absolute;
  width: 60%;
  height: 3px;
  background-color: #44C0B7;
  bottom: -15px;
  left: 20%;
}

.login-form {
  padding: 20px 0;
}

.input-item {
  display: flex;
  align-items: center;
  height: 50px;
  border: 1px solid #eee;
  border-radius: 5px;
  padding: 0 15px;
  margin-bottom: 20px;
}

.input-item input {
  flex: 1;
  height: 100%;
  margin-left: 10px;
  font-size: 15px;
}

.login-btn {
  width: 100%;
  height: 50px;
  background-color: #5EBEB8;
  color: #ffffff;
  border-radius: 5px;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 20px;
}

.third-party-login {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 40px;
}

.third-party-title {
  font-size: 14px;
  color: #999;
  margin-bottom: 20px;
}

.third-party-icons {
  display: flex;
  justify-content: center;
  width: 80%;
}

.icon-item {
  width: 40px;
  height: 40px;
  margin: 0 15px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.third-icon {
  width: 40px;
  height: 40px;
}

.mobile-login-link {
  margin-top: 20px;
  font-size: 14px;
  color: #666;
}

.link-text {
  color: #5EBEB8;
}
</style>